<template>
  <div class="box">
    <header>
      <div class="img"><img src="img/datouxiang33@2x.png" alt=""></div>
      <div class="right">
        <h2 v-if="status == '已发起'">{{infos.submitUser}}的精彩视频审批</h2>
        <h2 v-if="status != '已发起'">{{infos.submitUsername}}的精彩视频审批</h2>
        <p>{{status}}</p>
      </div>
    </header>
    <nav>
      <div class="body">
        <div class="title">发起人</div>
        <div class="content" v-if="status == '已发起'">{{infos.submitUser}}</div>
        <div class="content" v-if="status != '已发起'">{{infos.submitUsername}}</div>
        <div class="title">隶属校区/部门</div>
        <div class="content">{{infos.areaName}}</div>
        <!-- 课程审批详情 -->
        <div class="lesson">
          <div class="title">审批课程</div>
          <div class="content">{{infos.courseName}}-{{infos.className}}</div>
          <div class="title">上传文件</div>
          <!-- 展示列表 -->
          <div class="videoList">
            <img src="/img/videoTask/videoListImg.png" alt="" @click="preVideo">
          </div>
        </div>
        <div class="title">提交时间</div>
        <div class="content">{{infos.createTime}}</div>
        <div class="title">审批意见</div>
        <div class="content">{{infos.remark}}</div>
      </div>
      <div class="button" v-if="isShow"><button style="border-radius: 0.15rem 0 0 0.15rem;background:#2E9EFF" @click="pass(infos)">通过</button><button style="border-radius: 0 0.15rem 0.15rem 0;background:#FF2E2E" @click="refuse(infos)">拒绝</button></div>
    </nav>
    <!-- 视频预览 -->
    <div v-if="show" @click="cancelVideo" class="videoMask">
      <div class="wrapper">
        <div>
          <video-player class="video-player vjs-custom-skin" ref="videoPlayer" :playsinline="true" :options="playerOptions">
          </video-player>
        </div>
      </div>
    </div>
    <!-- 评论框 -->
    <van-dialog v-model="showCom" title="审批意见" show-cancel-button @confirm="onConfirm">
      <van-field v-model="message" rows="4" autosize type="textarea" maxlength="50" placeholder="请填写审批意见" show-word-limit />
    </van-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      show: false,
      showCom: false,
      message: "",
      playerOptions: {
        playbackRates: [0.5, 1.0, 1.5, 2.0], //倍速控制
        autoplay: false, //是否自动播放
        muted: false, //是否静音播放
        loop: false, //是否循环播放
        preload: "auto",
        language: "zh-CN", //语言，还要引入对应的文件
        aspectRatio: "16:9", //比例
        fluid: true,
        sources: [
          {
            type: "",
            src:
              "http://niu.icrobot.cn/ce468e3dda7c4d6a99dab17a517e77ad3-005-008%E8%AF%BE%E5%89%8D%E5%A4%8D%E4%B9%A0.mp4", //url地址
          },
        ],
        poster: "", //你的封面地址
        notSupportedMessage: "此视频暂无法播放，请稍后再试",
        controlBar: {
          timeDivider: true,
          durationDisplay: true, //剩余时间是否显示
          remainingTimeDisplay: false, //剩余时间是否显示，有一个即可
          fullscreenToggle: true, //全屏按钮
        },
      },
      isShow: false,
      taskId: "",
      infos: {},
      status: "",
      passStatus: "",
      submitUserId: ""
    };
  },
  mounted() {
    this.taskId = this.$route.query.taskId;
    this.infos = this.$route.query.infos;
    this.status = this.$route.query.status;
    this.queryInfo();
    if (this.$route.query.isShow == 1) {
      this.isShow=true;
    } else {
      this.isShow=false;
    }
  },
  methods: {
    // 详情数据
    queryInfo() {
      (async () => {
        const { data } = await this.get("/approve/queryBeiKeFile", {
          taskId: this.taskId,
        });
        this.playerOptions.sources[0].src=data[0].beikeFile;
      })();
    },
    // 待审批  预览视频
    preVideo() {
      this.$toast.loading({
        message: "加载中",
        duration: 500,
        onClose: () => {
          this.show = true;
        },
      });
    },
    cancelVideo() {
      this.show = false;
    },
    // 通过
    pass(infos) {
      this.showCom = true;
      this.passStatus = 2;
      this.submitUserId = infos.submitUser
    },
    // 拒绝
    refuse(infos) {
      this.showCom = true;
      this.passStatus = 3;
      this.submitUserId = infos.submitUser
    },
    // 点击确认
    onConfirm() {
      (
        async () => {
          const data = await this.get("/approve/wonderfulVideoPass",{
            status: this.passStatus,
            id: this.taskId,
            userId: this.submitUserId
          });
          if (data.code == 200) {
            this.$toast.success(data.msg);
            this.$router.back();
          } else {
            this.$toast.fail("请稍后再试");
          }
        }
      )()
    }
  },
};
</script>
<style lang="scss" scoped>
.box {
  height: 100%;
}
header {
  display: flex;
  align-items: center;
  padding: 0.2rem;
  .img {
    width: 0.72rem;
    height: 0.72rem;
    border-radius: 50%;
    img {
      width: 100%;
      height: 100%;
      vertical-align: top;
    }
  }
  .right {
    margin-left: 0.17rem;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    h2 {
      font-size: 0.3rem;
      font-family: PingFang SC;
      font-weight: bold;
      color: #343434;
    }
    p {
      font-size: 0.24rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #fa742a;
    }
  }
}
nav {
  border: 0.2rem solid #f7f9fa;
  height: 12rem;
  display: flex;
  flex-direction: column;
  border-radius: 0.15rem;
  .body {
    padding: 0 0.2rem 0.2rem;
    box-sizing: border-box;
    background: white;
    flex: 1;
    overflow: scroll;
    .title {
      margin-top: 0.3rem;
      font-size: 0.26rem;
      color: #787878;
    }
    .content {
      margin-top: 0.15rem;
      font-size: 0.28rem;
      font-family: PingFang SC;
      font-weight: bold;
      color: #333333;
    }
    .videoList {
      width: 6rem;
      display: flex;
      flex-wrap: wrap;
      img {
        width: 0.94rem;
        height: 0.94rem;
        margin-right: 0.2rem;
        margin-top: 0.2rem;
      }
    }
  }
  button {
    width: 50%;
    height: 0.84rem;
    //    border-radius: 0.15rem 0 0 0.15rem;
    border: none;
    font-size: 0.33rem;
    font-family: PingFang SC;
    font-weight: bold;
    color: #ffffff;
  }
}
.people {
  margin-top: 0.2rem;
  border-top: 0.01rem solid #eee;
}
.videoMask {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  .wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    div {
      width: 100%;
    }
  }
}
</style>